INC_all_loaded_imgs = {}
INC_all_loaded_fonts = {}
INC_all_loaded_colors = {}
INC_startdrawing = 0
INC_standard_fontsize = 11
INC_buffer_active = 0
INC_font = "verdana.ttf"
INC_printfont = 0

Controls = {}
screen = {}
Font = {}
Color = {}
Image = {}
System = {}
io = {}

buffer = pge.texture.create(480,272)

--##additional functions
function INC_check_color(color)
r = pge.gfx.red(color)
g = pge.gfx.green(color)
b = pge.gfx.blue(color)
a = pge.gfx.alpha(color)
found = false
if #INC_all_loaded_colors ~= 0 then 
        for i = 1,#INC_all_loaded_colors do 
                if not found then 
        check_r = pge.gfx.red(INC_all_loaded_colors[i])
        check_g = pge.gfx.green(INC_all_loaded_colors[i])
        check_b = pge.gfx.blue(INC_all_loaded_colors[i])
        check_a = pge.gfx.alpha(INC_all_loaded_colors[i])
                if r == check_r and g == check_g and b == check_b and a == check_a then 
                found = i
                end     
        end 
        end 
end 
return found
end

function INC_set_buffer()
	if INC_buffer_active == 0 then
		buffer:tovram()
		pge.texture.settarget(buffer)
		INC_buffer_active = 1
	end
end

function INC_unset_buffer()
	if INC_buffer_active == 1 then
		--pge.gfx.rendertoscreen()
		INC_buffer_active = 0
	end
end

function INC_move_buffer()
	buffer:toram()
end

function INC_drawing_enabled()
	if INC_startdrawing == 0 then
		pge.gfx.startdrawing()
		INC_startdrawing = 1
	end
end

--##CONTROLS
function Controls.read()
pgepad = {}
pge.controls.update()
    function pgepad:cross()
        if pge.controls.held(PGE_CTRL_CROSS) then 
        return true 
        end 
    end 
    function pgepad:square()
        if pge.controls.held(PGE_CTRL_SQUARE) then 
        return true 
        end 
    end 
    function pgepad:circle()
        if pge.controls.held(PGE_CTRL_CIRCLE) then 
        return true 
        end 
    end     
    function pgepad:triangle()
        if pge.controls.held(PGE_CTRL_TRIANGLE) then 
        return true 
        end 
    end     
    function pgepad:start()
        if pge.controls.held(PGE_CTRL_START) then 
        return true 
        end 
    end     
    function pgepad:select()
        if pge.controls.held(PGE_CTRL_SELECT) then 
        return true 
        end 
    end     
    function pgepad:up()
        if pge.controls.held(PGE_CTRL_UP) then 
        return true 
        end 
    end     
    function pgepad:down()
        if pge.controls.held(PGE_CTRL_DOWN) then 
        return true 
        end 
    end 
    function pgepad:left()
        if pge.controls.held(PGE_CTRL_LEFT) then 
        return true 
        end 
    end     
    function pgepad:right()
        if pge.controls.held(PGE_CTRL_RIGHT) then 
        return true 
        end 
    end 
    function pgepad:r()
        if pge.controls.held(PGE_CTRL_RTRIGGER) then 
        return true 
        end 
    end 
    function pgepad:l()
        if pge.controls.held(PGE_CTRL_LTRIGGER) then 
        return true 
        end 
    end     
	function pgepad:analogX()
		return pge.controls.analogx()
	end
	function pgepad:analogY()
		return pge.controls.analogy()
	end
    function pgepad:home()
    return false
    end
    function pgepad:note()
    return false
    end     
    function pgepad:screen()
    return false
    end     
    function pgepad:hold()
    return false
    end 
    function pgepad:wlan()
	    return pge.net.switchstatus()
    end    
return pgepad
end 

function Controls.wlan()
	return pge.net.switchstatus()
end

--##COLOR
function Color.new(r,g,b,a)
        if not a then
                a = 255
        end
        pre_pos = INC_check_color(pge.gfx.createcolor(r,g,b,a))
       if pre_pos then 
          num = pre_pos
          INC_color_table = {id =  pre_pos}
        else
        INC_all_loaded_colors[#INC_all_loaded_colors+1] = pge.gfx.createcolor(r,g,b,a)
          num = #INC_all_loaded_colors
          INC_color_table = {id = #INC_all_loaded_colors}
      end 
        
        function INC_color_table:colors()
                return {r = pge.gfx.red(INC_all_loaded_colors[num]),g = pge.gfx.green(INC_all_loaded_colors[num]),b = pge.gfx.blue(INC_all_loaded_colors[num]),a =pge.gfx.alpha(INC_all_loaded_colors[num])}
        end
return INC_color_table
end

--##SCREEN
function screen.flip()
        INC_drawing_enabled()
		INC_unset_buffer()
        pge.gfx.rendertoscreen()
          buffer:activate()
          buffer:draw(0,0)
        pge.gfx.enddrawing()
        INC_startdrawing = 0
end
 
function screen.waitVblankStart(wait)
        pge.gfx.swapbuffers()
        if wait then
                pge.delay(wait*10)
        end
end
 
function screen:clear(color)
        if not color then
        color = Color.new(0,0,0)
        end
        INC_drawing_enabled()
        INC_set_buffer()
        pge.gfx.clearscreen(INC_all_loaded_colors[color.id])
end
 
function screen:save(path)
        pge.gfx.screenshot(path)
end
 
function screen:drawLine(x0, y0, x1, y1, color)
        INC_drawing_enabled()
		INC_set_buffer()
        pge.gfx.drawline(x0, y0, x1, y1, INC_all_loaded_colors[color.id])
end
 
function screen:print(x ,y ,text,color)
        if INC_printfont == 0 then
				INC_all_loaded_fonts[#INC_all_loaded_fonts+1] = pge.font.load(INC_font,INC_standard_fontsize, PGE_RAM)
				INC_printfont = #INC_all_loaded_fonts
        end
        INC_drawing_enabled()
		INC_set_buffer()
        pge.font.activate(INC_all_loaded_fonts[INC_printfont])
        pge.font.print(INC_all_loaded_fonts[INC_printfont], x, y, INC_all_loaded_colors[color.id], text)
end
 
function screen:blit(x,y,img,sourcex, sourcey, width, height, alpha)
        if not sourcex then
                sourcex = 0
        end
        if not sourcey then
                sourcey = 0
        end
        if not width then
                width = INC_all_loaded_imgs[img.id]:width()
        end
        if not height then
                height = INC_all_loaded_imgs[img.id]:height()
        end
        if not alpha then
                alpha = false
        end
        INC_drawing_enabled()
		INC_set_buffer()
        INC_all_loaded_imgs[img.id]:activate()
        INC_all_loaded_imgs[img.id]:draw(x, y, INC_all_loaded_imgs[img.id]:width(), INC_all_loaded_imgs[img.id]:height(), sourcex, sourcey, width, height)
end
 
function screen:fontPrint(font, x, y, text, color)
        INC_drawing_enabled()
		INC_set_buffer()
        pge.font.activate(INC_all_loaded_fonts[font.id])
        pge.font.print(INC_all_loaded_fonts[font.id], x, y, INC_all_loaded_colors[color.id], text)
end
 
function screen:fillRect(x, y, width, height, color)
        INC_drawing_enabled()
		INC_set_buffer()
        pge.gfx.drawrect(x, y, width, height, INC_all_loaded_colors[color.id])
end
 
 
function screen:width()
        return 480
end
 
function screen:height()
        return 272
end
 
function screen:pixel(x, y , color)
        INC_drawing_enabled()
        if not color then
                PXpgecolor = pge.texture.pixel(buffer, x, y)
                PXcolor = Color.new(pge.gfx.red(PXpgecolor),pge.gfx.green(PXpgecolor),pge.gfx.blue(PXpgecolor),pge.gfx.alpha(PXpgecolor))
        return PXcolor
        else
			pge.texture.pixel(buffer,x,y,INC_all_loaded_colors[color.id])
        end
end

--##FONT

function Font.load(file)
	INC_all_loaded_fonts[#INC_all_loaded_fonts+1] = pge.font.load(file, INC_standard_fontsize, PGE_RAM)
	local font_table = {id = #INC_all_loaded_fonts}
	local num = #INC_all_loaded_fonts
	function font_table:setPixelSizes(width, height)
		if not height then height = width*1.25 end
		INC_all_loaded_fonts[num] = pge.font.load(file, height)
	end
	function font_table:getTextSize(_string)
		return pge.font.measure(INC_all_loaded_fonts[num], _string)
	end
	return font_table
end

function Font.init()
	return true
end

--##IMAGE
function Image.load(path)
	INC_all_loaded_imgs[#INC_all_loaded_imgs+1] = pge.texture.load(path, PGE_RAM)
	local imgnum = #INC_all_loaded_imgs
	local img_table = {id = #INC_all_loaded_imgs}
	function img_table:pixel(x,y,color)
        local num = imgnum
		INC_drawing_enabled()
		if not color then
			PXcolor = pge.texture.pixel(INC_all_loaded_imgs[num], x, y)
			return PXcolor
		else
			pge.texture.pixel(INC_all_loaded_imgs[num], x, y, INC_all_loaded_colors[color.id])
		end
    end
	function img_table:width()
		return pge.texture.width(INC_all_loaded_imgs[imgnum])
	end
	function img_table:height()
		return pge.texture.height(INC_all_loaded_imgs[imgnum])
	end
	function img_table:save(path)
		pge.texture.unswizzle(INC_all_loaded_imgs[imgnum])
		pge.texture.save(INC_all_loaded_imgs[imgnum], path)
		pge.texture.swizzle(INC_all_loaded_imgs[imgnum])
	end
	function img_table:clear(color)
		INC_drawing_enabled()
		if not color then 
			color = Color.new(0,0,0)
		end 
		local width = pge.texture.width(INC_all_loaded_imgs[imgnum])
		local height = pge.texture.height(INC_all_loaded_imgs[imgnum])
		INC_all_loaded_imgs[imgnum] = pge.texture.create(width,height)
		INC_unset_buffer()
		INC_move_buffer()
		INC_all_loaded_imgs[imgnum]:tovram()
		INC_all_loaded_imgs[imgnum]:settarget()
		pge.gfx.clearscreen(INC_all_loaded_colors[color.id])
		pge.gfx.swapbuffers()
		INC_all_loaded_imgs[imgnum]:toram()
		--[[pge.texture.unswizzle(INC_all_loaded_imgs[imgnum])
		for y = 1, pge.texture.height(INC_all_loaded_imgs[imgnum]) do
			for x = 1, pge.texture.width(INC_all_loaded_imgs[imgnum]) do
				pge.texture.pixel(INC_all_loaded_imgs[imgnum], x-1, y-1, INC_all_loaded_colors[color.id])
			end
		end
		pge.texture.swizzle(INC_all_loaded_imgs[imgnum])]]
		--[[INC_unset_buffer()
		INC_move_buffer()
		pge.texture.unswizzle(INC_all_loaded_imgs[imgnum])
		INC_all_loaded_imgs[imgnum]:tovram()
		INC_all_loaded_imgs[imgnum]:settarget()
		pge.gfx.clearscreen(INC_all_loaded_colors[color.id])
		INC_all_loaded_imgs[imgnum]:toram()
		pge.texture.swizzle(INC_all_loaded_imgs[imgnum])
		pge.gfx.swapbuffers()
		pge.gfx.swapbuffers()]]
	end
	function img_table:blit(x,y,img,sourcex, sourcey, width, height, alpha)
		if not sourcex then 
			sourcex = 0
		end 
		if not sourcey then 
			sourcey = 0
		end 
		if not width then 
			width = INC_all_loaded_imgs[img.id]:width()
		end 
		if not height then 
			height = INC_all_loaded_imgs[img.id]:height()
		end 
		if not alpha then
			alpha = 255
		else
			alpha = 255
		end
		if not blit_done then blit_done = {} end
		do_blit = 1
		for i=1,#blit_done do
			if blit_done[i][1] == img and blit_done[i][2] == x and blit_done[i][3] == y then
				do_blit = 0
			break end
		end
		if do_blit == 1 then
			INC_drawing_enabled()
			INC_unset_buffer()
			INC_move_buffer()
			pge.texture.unswizzle(INC_all_loaded_imgs[imgnum])
			pge.texture.unswizzle(INC_all_loaded_imgs[img.id])
			INC_all_loaded_imgs[imgnum]:tovram()
			INC_all_loaded_imgs[imgnum]:settarget()
				INC_all_loaded_imgs[img.id]:activate()
				INC_all_loaded_imgs[img.id]:draw(x, y, width, height, sourcex, sourcex, width, height, 0, alpha)
			INC_all_loaded_imgs[imgnum]:toram()
			--[[for py = 1, pge.texture.height(INC_all_loaded_imgs[img.id]) do
				for px = 1, pge.texture.width(INC_all_loaded_imgs[img.id]) do
					pge.texture.pixel(INC_all_loaded_imgs[num], x+(px-1), y+(py-1), pge.texture.pixel(INC_all_loaded_imgs[img.id],px,py))
				end
			end]]
			pge.texture.swizzle(INC_all_loaded_imgs[imgnum])
			pge.texture.swizzle(INC_all_loaded_imgs[img.id])
			table.insert(blit_done, {img, x, y})
		end
	end
	function img_table:drawLine(x0, y0, x1, y1, color)
		if not drawLine_done then drawLine_done = {} end
		do_drawLine = 1
		for i=1,#drawLine_done do
			if drawLine_done[i][1] == x0 and drawLine_done[i][2] == y0 and drawLine_done[i][3] == x1 and drawLine_done[i][4] == y1 then
				do_drawLine = 0
			break end
		end
		if do_drawLine == 1 then
			INC_drawing_enabled()
			INC_unset_buffer()
			INC_move_buffer()
			pge.texture.unswizzle(INC_all_loaded_imgs[imgnum])
			INC_all_loaded_imgs[imgnum]:tovram()
			INC_all_loaded_imgs[imgnum]:settarget()
				pge.gfx.drawline(x0, y0, x1, y1, INC_all_loaded_colors[color.id])
			INC_all_loaded_imgs[imgnum]:toram()
			--[[local delta_x = x1-x0
			local delta_y = y1-y0
			local m = delta_y/delta_x
			for i = 1, delta_x do
				--if m*i == math.ceil(m*i) then
					pge.texture.pixel(INC_all_loaded_imgs[num],x0+(i-1),y0+m*i,INC_all_loaded_colors[color.id])
				--end
			end]]
			pge.texture.swizzle(INC_all_loaded_imgs[imgnum])
			table.insert(drawLine_done, {x0, y0, x1, y1})
		end
	end
	function img_table:print(x,y,text,color)
		if INC_printfont == 0 then
				INC_all_loaded_fonts[#INC_all_loaded_fonts+1] = pge.font.load(INC_font,INC_standard_fontsize, PGE_RAM)
				INC_printfont = #INC_all_loaded_fonts
        end
		if not print_done then print_done = {} end
		do_print = 1
		for i=1,#print_done do
			if print_done[i][1] == x and print_done[i][2] == y and print_done[i][3] == text and print_done[i][4] == color then
				do_print = 0
			break end
		end
		if do_print == 1 then
			INC_drawing_enabled()
			INC_unset_buffer()
			INC_move_buffer()
			pge.texture.unswizzle(INC_all_loaded_imgs[imgnum])
			INC_all_loaded_imgs[imgnum]:tovram()
			INC_all_loaded_imgs[imgnum]:settarget()
				pge.font.activate(INC_all_loaded_fonts[INC_printfont])
				pge.font.print(INC_all_loaded_fonts[INC_printfont], x, y, INC_all_loaded_colors[color.id], text)
			INC_all_loaded_imgs[imgnum]:toram()
			pge.texture.swizzle(INC_all_loaded_imgs[imgnum])
			table.insert(print_done, {x, y, text, color})
		end
	end
	function img_table:fontPrint(font,x,y,text,color)
		if not fontprint_done then fontprint_done = {} end
		do_fontprint = 1
		for i=1,#fontprint_done do
			if fontprint_done[i][1] == x and fontprint_done[i][2] == y and fontprint_done[i][3] == text and fontprint_done[i][4] == color and fontprint_done[i][5] == font then
				do_fontprint = 0
			break end
		end
		if do_fontprint == 1 then
			INC_drawing_enabled()
			INC_unset_buffer()
			INC_move_buffer()
			pge.texture.unswizzle(INC_all_loaded_imgs[imgnum])
			INC_all_loaded_imgs[imgnum]:tovram()
			INC_all_loaded_imgs[imgnum]:settarget()
				pge.font.activate(INC_all_loaded_fonts[font.id])
				pge.font.print(INC_all_loaded_fonts[font.id], x, y, INC_all_loaded_colors[color.id], text)
			INC_all_loaded_imgs[imgnum]:toram()
			pge.texture.swizzle(INC_all_loaded_imgs[imgnum])
			table.insert(fontprint_done, {x, y, text, color, font})
		end
	end
	function img_table:fillRect(x, y, width, height, color)
		if not fillRect_done then fillRect_done = {} end
		do_fillRect = 1
		for i=1,#fillRect_done do
			if fillRect_done[i][1] == x and fillRect_done[i][2] == y and fillRect_done[i][3] == width and fillRect_done[i][4] == height and fillRect_done[i][5] == color then
				do_fillRect = 0
			break end
		end
		if do_fillRect == 1 then
			INC_drawing_enabled()
			INC_unset_buffer()
			INC_move_buffer()
			pge.texture.unswizzle(INC_all_loaded_imgs[imgnum])
			INC_all_loaded_imgs[imgnum]:tovram()
			INC_all_loaded_imgs[imgnum]:settarget()
				pge.gfx.drawrect(x, y, width, height, INC_all_loaded_colors[color.id], 0)
			INC_all_loaded_imgs[imgnum]:toram()
			--[[for py = 1, height do
				for px = 1, width do
					pge.texture.pixel(INC_all_loaded_imgs[num],x+(px-1),y+(py-1),INC_all_loaded_colors[color.id])
				end
			end]]
			pge.texture.swizzle(INC_all_loaded_imgs[imgnum])
			table.insert(fillRect_done, {x, y, width, height, color})
		end
	end
return img_table
end 

function Image.createEmpty(w,h)
	INC_all_loaded_imgs[#INC_all_loaded_imgs+1] = pge.texture.create(w,h)
	local imgnum = #INC_all_loaded_imgs
	local img_table = {id = #INC_all_loaded_imgs}
	function img_table:pixel(x,y,color)
        local num = imgnum
		INC_drawing_enabled()
		if not color then
			PXcolor = pge.texture.pixel(INC_all_loaded_imgs[num], x, y)
			return PXcolor
		else
			pge.texture.pixel(INC_all_loaded_imgs[num], x, y, INC_all_loaded_colors[color.id])
		end
    end
	function img_table:width()
		return pge.texture.width(INC_all_loaded_imgs[imgnum])
	end
	function img_table:height()
		return pge.texture.height(INC_all_loaded_imgs[imgnum])
	end
	function img_table:save(path)
		pge.texture.unswizzle(INC_all_loaded_imgs[imgnum])
		pge.texture.save(INC_all_loaded_imgs[imgnum], path)
		pge.texture.swizzle(INC_all_loaded_imgs[imgnum])
	end
	function img_table:clear(color)
		INC_drawing_enabled()
		if not color then 
			color = Color.new(0,0,0)
		end 
		local width = pge.texture.width(INC_all_loaded_imgs[imgnum])
		local height = pge.texture.height(INC_all_loaded_imgs[imgnum])
		INC_all_loaded_imgs[imgnum] = pge.texture.create(width,height)
		INC_unset_buffer()
		INC_move_buffer()
		INC_all_loaded_imgs[imgnum]:tovram()
		INC_all_loaded_imgs[imgnum]:settarget()
		pge.gfx.clearscreen(INC_all_loaded_colors[color.id])
		pge.gfx.swapbuffers()
		INC_all_loaded_imgs[imgnum]:toram()
		--[[pge.texture.unswizzle(INC_all_loaded_imgs[imgnum])
		for y = 1, pge.texture.height(INC_all_loaded_imgs[imgnum]) do
			for x = 1, pge.texture.width(INC_all_loaded_imgs[imgnum]) do
				pge.texture.pixel(INC_all_loaded_imgs[imgnum], x-1, y-1, INC_all_loaded_colors[color.id])
			end
		end
		pge.texture.swizzle(INC_all_loaded_imgs[imgnum])]]
		--[[INC_unset_buffer()
		INC_move_buffer()
		pge.texture.unswizzle(INC_all_loaded_imgs[imgnum])
		INC_all_loaded_imgs[imgnum]:tovram()
		INC_all_loaded_imgs[imgnum]:settarget()
		pge.gfx.clearscreen(INC_all_loaded_colors[color.id])
		INC_all_loaded_imgs[imgnum]:toram()
		pge.texture.swizzle(INC_all_loaded_imgs[imgnum])
		pge.gfx.swapbuffers()
		pge.gfx.swapbuffers()]]
	end
	function img_table:blit(x,y,img,sourcex, sourcey, width, height, alpha)
		if not sourcex then 
			sourcex = 0
		end 
		if not sourcey then 
			sourcey = 0
		end 
		if not width then 
			width = INC_all_loaded_imgs[img.id]:width()
		end 
		if not height then 
			height = INC_all_loaded_imgs[img.id]:height()
		end 
		if not alpha then
			alpha = 255
		else
			alpha = 255
		end
		if not blit_done then blit_done = {} end
		do_blit = 1
		for i=1,#blit_done do
			if blit_done[i][1] == img and blit_done[i][2] == x and blit_done[i][3] == y then
				do_blit = 0
			break end
		end
		if do_blit == 1 then
			INC_drawing_enabled()
			INC_unset_buffer()
			INC_move_buffer()
			pge.texture.unswizzle(INC_all_loaded_imgs[imgnum])
			pge.texture.unswizzle(INC_all_loaded_imgs[img.id])
			INC_all_loaded_imgs[imgnum]:tovram()
			INC_all_loaded_imgs[imgnum]:settarget()
				INC_all_loaded_imgs[img.id]:activate()
				INC_all_loaded_imgs[img.id]:draw(x, y, width, height, sourcex, sourcex, width, height, 0, alpha)
			INC_all_loaded_imgs[imgnum]:toram()
			--[[for py = 1, pge.texture.height(INC_all_loaded_imgs[img.id]) do
				for px = 1, pge.texture.width(INC_all_loaded_imgs[img.id]) do
					pge.texture.pixel(INC_all_loaded_imgs[num], x+(px-1), y+(py-1), pge.texture.pixel(INC_all_loaded_imgs[img.id],px,py))
				end
			end]]
			pge.texture.swizzle(INC_all_loaded_imgs[imgnum])
			pge.texture.swizzle(INC_all_loaded_imgs[img.id])
			table.insert(blit_done, {img, x, y})
		end
	end
	function img_table:drawLine(x0, y0, x1, y1, color)
		if not drawLine_done then drawLine_done = {} end
		do_drawLine = 1
		for i=1,#drawLine_done do
			if drawLine_done[i][1] == x0 and drawLine_done[i][2] == y0 and drawLine_done[i][3] == x1 and drawLine_done[i][4] == y1 then
				do_drawLine = 0
			break end
		end
		if do_drawLine == 1 then
			INC_drawing_enabled()
			INC_unset_buffer()
			INC_move_buffer()
			pge.texture.unswizzle(INC_all_loaded_imgs[imgnum])
			INC_all_loaded_imgs[imgnum]:tovram()
			INC_all_loaded_imgs[imgnum]:settarget()
				pge.gfx.drawline(x0, y0, x1, y1, INC_all_loaded_colors[color.id])
			INC_all_loaded_imgs[imgnum]:toram()
			--[[local delta_x = x1-x0
			local delta_y = y1-y0
			local m = delta_y/delta_x
			for i = 1, delta_x do
				--if m*i == math.ceil(m*i) then
					pge.texture.pixel(INC_all_loaded_imgs[num],x0+(i-1),y0+m*i,INC_all_loaded_colors[color.id])
				--end
			end]]
			pge.texture.swizzle(INC_all_loaded_imgs[imgnum])
			table.insert(drawLine_done, {x0, y0, x1, y1})
		end
	end
	function img_table:print(x,y,text,color)
		if INC_printfont == 0 then
				INC_all_loaded_fonts[#INC_all_loaded_fonts+1] = pge.font.load(INC_font,INC_standard_fontsize, PGE_RAM)
				INC_printfont = #INC_all_loaded_fonts
        end
		if not print_done then print_done = {} end
		do_print = 1
		for i=1,#print_done do
			if print_done[i][1] == x and print_done[i][2] == y and print_done[i][3] == text and print_done[i][4] == color then
				do_print = 0
			break end
		end
		if do_print == 1 then
			INC_drawing_enabled()
			INC_unset_buffer()
			INC_move_buffer()
			pge.texture.unswizzle(INC_all_loaded_imgs[imgnum])
			INC_all_loaded_imgs[imgnum]:tovram()
			INC_all_loaded_imgs[imgnum]:settarget()
				pge.font.activate(INC_all_loaded_fonts[INC_printfont])
				pge.font.print(INC_all_loaded_fonts[INC_printfont], x, y, INC_all_loaded_colors[color.id], text)
			INC_all_loaded_imgs[imgnum]:toram()
			pge.texture.swizzle(INC_all_loaded_imgs[imgnum])
			table.insert(print_done, {x, y, text, color})
		end
	end
	function img_table:fontPrint(font,x,y,text,color)
		if not fontprint_done then fontprint_done = {} end
		do_fontprint = 1
		for i=1,#fontprint_done do
			if fontprint_done[i][1] == x and fontprint_done[i][2] == y and fontprint_done[i][3] == text and fontprint_done[i][4] == color and fontprint_done[i][5] == font then
				do_fontprint = 0
			break end
		end
		if do_fontprint == 1 then
			INC_drawing_enabled()
			INC_unset_buffer()
			INC_move_buffer()
			pge.texture.unswizzle(INC_all_loaded_imgs[imgnum])
			INC_all_loaded_imgs[imgnum]:tovram()
			INC_all_loaded_imgs[imgnum]:settarget()
				pge.font.activate(INC_all_loaded_fonts[font.id])
				pge.font.print(INC_all_loaded_fonts[font.id], x, y, INC_all_loaded_colors[color.id], text)
			INC_all_loaded_imgs[imgnum]:toram()
			pge.texture.swizzle(INC_all_loaded_imgs[imgnum])
			table.insert(fontprint_done, {x, y, text, color, font})
		end
	end
	function img_table:fillRect(x, y, width, height, color)
		if not fillRect_done then fillRect_done = {} end
		do_fillRect = 1
		for i=1,#fillRect_done do
			if fillRect_done[i][1] == x and fillRect_done[i][2] == y and fillRect_done[i][3] == width and fillRect_done[i][4] == height and fillRect_done[i][5] == color then
				do_fillRect = 0
			break end
		end
		if do_fillRect == 1 then
			INC_drawing_enabled()
			INC_unset_buffer()
			INC_move_buffer()
			pge.texture.unswizzle(INC_all_loaded_imgs[imgnum])
			INC_all_loaded_imgs[imgnum]:tovram()
			INC_all_loaded_imgs[imgnum]:settarget()
				pge.gfx.drawrect(x, y, width, height, INC_all_loaded_colors[color.id], 0)
			INC_all_loaded_imgs[imgnum]:toram()
			--[[for py = 1, height do
				for px = 1, width do
					pge.texture.pixel(INC_all_loaded_imgs[num],x+(px-1),y+(py-1),INC_all_loaded_colors[color.id])
				end
			end]]
			pge.texture.swizzle(INC_all_loaded_imgs[imgnum])
			table.insert(fillRect_done, {x, y, width, height, color})
		end
	end
return img_table
end 

--##SYSTEM

function System.Quit()
	pge.exit()
end







